package com.datastructure.test.recall.childrenofarray.self;

import java.util.*;

public class TotalOfChildrenArray {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        byte[] bytes = s.getBytes();
        boolean[] isUsed = new boolean[bytes.length];
        List<List<Byte>> res = new ArrayList<>();
        Deque<Byte> deque = new ArrayDeque<>();
        getTotalOfChildrenArray(bytes,isUsed,res,deque,0);
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        String s1;
        for (int j = 0; j < res.size(); j++) {
            List<Byte> list=res.get(j);
            byte[] bts = new byte[list.size()];
            for (int i = 0; i < list.size(); i++) {
                bts[i]=list.get(i);
            }
            if(j==res.size()-1){
                s1 = "'"+new String(bts)+"'";
                stringBuilder.append(s1);
            } else {
                s1 = "'"+new String(bts)+"',";
                stringBuilder.append(s1);
            }
        }
        stringBuilder.append("]");
        System.out.println(stringBuilder);
    }

    public static void getTotalOfChildrenArray(byte[] data, boolean[] isUsed, List<List<Byte>> res, Deque<Byte> deque,int depth){
        if(depth== data.length){
            res.add(new ArrayList<>(deque));
            return;
        }
        for (int i = 0; i < data.length; i++) {
            if(isUsed[i]){
                continue;
            }
            if(i>0&&data[i]==data[i-1]&&!isUsed[i-1]){
                continue;
            }
            isUsed[i]=true;
            deque.add(data[i]);
            getTotalOfChildrenArray(data, isUsed, res, deque,depth+1);
            isUsed[i]=false;
            deque.removeLast();
        }
    }
}
